#!/usr/bin/env bash

#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

log_level=${log_level:=info}

assist_dir=`cd $this_script_dir/assist && pwd`
source "$assist_dir/global.sh"

while true
do
    hour=`date +%H`
    day=`date +%d`
    today=0
    today_alread_push=false


    if [ $today -ne $day ] ; then
        today_already_push=false
    fi

    #if [ $hour -gt 18 -a $hour -lt 24 ] && [ $today -ne $day ] && [ $today_already_push == "false" ]; then
    if [ $hour -gt 18 -a $hour -lt 24 ] ; then
        vlogi "run push_all.sh" 
        #today=$day
        #today_already_push=true
        $HOME/git/push_all.sh
        timeout=3600  #sleep an hour
        sleep $timeout
    else
        timeout=1800  #half hour walkup to check
        vlogi "condion is not archive[$hour -eq 18 ,$today -ne $day,$today_already_push == false], sleep $timeout sec ..."
        sleep $timeout
    fi
done

exit 0

